package com.ruoyi.medical.service.impl;

import java.util.List;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.common.utils.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.medical.mapper.TreatmentMapper;
import com.ruoyi.medical.domain.Treatment;
import com.ruoyi.medical.service.ITreatmentService;

/**
 * 就诊信息Service业务层处理
 *
 * @author ruoyi
 * @date 2024-02-29
 */
@Service
public class TreatmentServiceImpl implements ITreatmentService
{
    @Autowired
    private TreatmentMapper treatmentMapper;

    /**
     * 查询就诊信息
     *
     * @param id 就诊信息主键
     * @return 就诊信息
     */
    @Override
    public Treatment selectTreatmentById(Long id)
    {
        return treatmentMapper.selectTreatmentById(id);
    }

    /**
     * 查询就诊信息列表
     *
     * @param treatment 就诊信息
     * @return 就诊信息
     */
    @Override
    public List<Treatment> selectTreatmentList(Treatment treatment)
    {
        return treatmentMapper.selectTreatmentList(treatment);
    }

    /**
     * 新增就诊信息
     *
     * @param treatment 就诊信息
     * @return 结果
     */
    @Override
    public int insertTreatment(Treatment treatment)
    {
        treatment.setCreateTime(DateUtils.getNowDate());
        //CreateBy
        String username = SecurityUtils.getUsername();
        if (StringUtils.isEmpty(username)){
            throw new RuntimeException("用户名不存在");
        }else {
            treatment.setCreateBy(username);
        }
        return treatmentMapper.insertTreatment(treatment);
    }

    /**
     * 修改就诊信息
     *
     * @param treatment 就诊信息
     * @return 结果
     */
    @Override
    public int updateTreatment(Treatment treatment)
    {
        treatment.setUpdateTime(DateUtils.getNowDate());
        //UpdateBy
        String username = SecurityUtils.getUsername();
        if (StringUtils.isEmpty(username)){
            throw new RuntimeException("用户名不存在");
        }else {
            treatment.setUpdateBy(username);
        }
        return treatmentMapper.updateTreatment(treatment);
    }

    /**
     * 批量删除就诊信息
     *
     * @param ids 需要删除的就诊信息主键
     * @return 结果
     */
    @Override
    public int deleteTreatmentByIds(Long[] ids)
    {
        return treatmentMapper.deleteTreatmentByIds(ids);
    }

    /**
     * 删除就诊信息信息
     *
     * @param id 就诊信息主键
     * @return 结果
     */
    @Override
    public int deleteTreatmentById(Long id)
    {
        return treatmentMapper.deleteTreatmentById(id);
    }
}
